//
//  ZoreShopingController.m
//  OneDoller
//
//  Created by jt on 16/8/16.
//  Copyright © 2016年 jyj. All rights reserved.
//

#import "ZoreShopingController.h"
#import "NewLinesCollectionViewCell.h"
#import "PupilsCollectionViewCell.h"
#import "SeachViewController.h"

#define Width ([UIScreen mainScreen].bounds.size.width)
#define Height ([UIScreen mainScreen].bounds.size.height)
@interface ZoreShopingController()<UICollectionViewDelegate,UICollectionViewDataSource>
//@property (weak, nonatomic) IBOutlet UIScrollView *BottomScrollView;

//@property (weak, nonatomic) IBOutlet UICollectionView *NewCollectionView;

@property (strong,nonatomic) UICollectionView *NewCollectionView;
@property (strong,nonatomic) UICollectionView *PupilsCollectionView;
//@property (strong,nonatomic) UIScrollView *scrollView;


@end
@implementation ZoreShopingController

- (instancetype) init{
    
    self = [super init];
    
    if (self) {
        
        //我们也可以在子页中自定义一个返回按钮覆盖原先的"<back"
//        UIBarButtonItem *barBtn5=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"pencil.png"] style:UIBarButtonItemStylePlain target:self action:@selector(backTo)];
////        UIBarButtonItem *barBtn5=[[UIBarButtonItem alloc]initWithTitle:@"go" style:UIBarButtonItemStylePlain target:self action:@selector(backTo)];
//        self.navigationItem.leftBarButtonItem=barBtn5;
//        //设置导航标题，这个时候的返回按钮的title就是上一级的navigationItem的title文字
//        [self.navigationItem setTitle:@"0元夺宝"];
//        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(seach)];
//
        [self collectionView];
//
////        [self addMessageCategoryButton];
//        
//        self.view.backgroundColor = [UIColor whiteColor];
//        [self.view addSubview:_topView];
        
        
        [self.view addSubview:_NewCollectionView];
        
//        [self.view addSubview:_PupilsCollectionView];
        
        
        
           

        
    }
    return self;

}
#pragma mark - seach
- (IBAction)Search:(id)sender {
    
    self.tabBarController.tabBar.hidden=YES;
    self.hidesBottomBarWhenPushed=YES;
    SeachViewController *seachView = [[SeachViewController alloc] init];
    [self.navigationController pushViewController:seachView animated:YES];
}

#pragma mark - backTo

- (IBAction)backTo:(id)sender {
        [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
}



#pragma mark - 创建collectionView并设置代理
- (void)collectionView{
   
    if (_NewCollectionView == nil) {
        
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        
        flowLayout.headerReferenceSize = CGSizeMake(Width, 50);//头部大小
        
        _NewCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, Width, Height) collectionViewLayout:flowLayout];
        _PupilsCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(Width, 0, Width, Height) collectionViewLayout:flowLayout];
        
        //定义每个UICollectionView 的大小
        flowLayout.itemSize = CGSizeMake((Width-20)/2, (Width-20)/2+50);
        //定义每个UICollectionView 横向的间距
        flowLayout.minimumLineSpacing = 5;
        //定义每个UICollectionView 纵向的间距
        flowLayout.minimumInteritemSpacing = 0;
        //定义每个UICollectionView 的边距距
        flowLayout.sectionInset = UIEdgeInsetsMake(0, 5, 5, 5);//上左下右
        
        //注册cell

        [_NewCollectionView registerClass:[NewLinesCollectionViewCell class] forCellWithReuseIdentifier:@"cell1"];
        [_PupilsCollectionView registerClass:[PupilsCollectionViewCell class] forCellWithReuseIdentifier:@"cell2"];

        //设置代理
        _NewCollectionView.delegate = self;
        _NewCollectionView.dataSource = self;
        _PupilsCollectionView.delegate = self;
        _PupilsCollectionView.dataSource = self;
        
        //背景颜色
        _NewCollectionView.backgroundColor = [UIColor whiteColor];
        _PupilsCollectionView.backgroundColor = [UIColor blueColor];
        //自适应大小
        _NewCollectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        _PupilsCollectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        
    }
   
}



#pragma mark - UICollectionView delegate dataSource
#pragma mark 定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
  
    return 10;
}

#pragma mark 定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

#pragma mark 每个UICollectionView展示的内容

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    
        NewLinesCollectionViewCell *Newcell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell1" forIndexPath:indexPath];
        
            [Newcell sizeToFit];
        Newcell.imageV.image = [UIImage imageNamed:@"零元夺宝进入按钮.png"];
        Newcell.productLabel.text = [NSString stringWithFormat:@"第%ld期:",indexPath.row];
        
        Newcell.ProgressView.progress = 0.7;
        Newcell.surplusNumber.text = [NSString stringWithFormat:@"剩余:%ld人次",indexPath.row * 10];

    
    return Newcell;
}






@end
